package com.vision.controller;

import com.github.pagehelper.Page;
import com.vision.pojo.AjaxResult;
import com.vision.pojo.vo.PageVO;
import com.vision.pojo.vo.UserFollowVO;
import com.vision.service.UserFollowService;
import org.apache.ibatis.annotations.Delete;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userFollow")
public class UserFollowController {
    @Autowired
    private UserFollowService userFollowService;

    /**
     * 获取粉丝列表
     * @param pageNum 当前页码
     * @param pageSize 每页显示的条数
     * @return 粉丝列表
     */
    @GetMapping("/getFansForPage")
    public AjaxResult<PageVO<UserFollowVO>> getFansForPage (@NotNull Integer pageNum,@NotNull Integer pageSize,@NotNull Integer userId) {
        return AjaxResult.success(userFollowService.getFansForPage(pageNum,pageSize,userId));
    }

    /**
     * 获取关注列表
     * @param pageNum 当前页码
     * @param pageSize 每页显示的条数
     * @return 关注列表
     */
    @GetMapping("/getSubscriptionForPage")
    public AjaxResult<PageVO<UserFollowVO>> getSubscriptionForPage (@NotNull Integer pageNum,@NotNull Integer pageSize,@NotNull Integer userId) {
        return AjaxResult.success(userFollowService.getSubscriptionForPage(pageNum,pageSize,userId));
    }

    /**
     * 删除粉丝
     * @param followerId 粉丝 id
     * @return 删除结果
     */
    @DeleteMapping("/deleteFan")
    public AjaxResult deleteFan (@NotNull Integer followerId){
        userFollowService.deleteFan(followerId);
        return AjaxResult.success();
    }

    /**
     * 关注
     * @param targetUserId 用户 id
     * @return 关注结果
     */
    @PostMapping("/subscribe")
    public AjaxResult subscribe(@NotNull Integer targetUserId){
        userFollowService.subscribe(targetUserId);
        return AjaxResult.success();
    }

    /**
     * 取消关注
     * @param targetUserId 用户 id
     * @return 取消关注结果
     */
    @DeleteMapping("/cancelSubscribe")
    public AjaxResult cancelSubscribe(@NotNull Integer targetUserId){
        userFollowService.cancelSubscribe(targetUserId);
        return AjaxResult.success();
    }

}
